package com.nys.cqhttp.message.factory.impl;

import cn.hutool.http.HttpUtil;
import com.nys.cqhttp.mapper.*;
import com.nys.cqhttp.message.factory.IMessageHandler;
import com.nys.cqhttp.model.*;
import com.nys.cqhttp.param.Context;
import com.nys.cqhttp.param.MessageParam;
import com.nys.cqhttp.util.DateUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import java.io.File;
import java.util.*;

/**
 * DirectUrlMessageHandler
 *
 * @author nysheng
 * @version 1.0.0
 * @description 钓鱼
 * @date 2021/12/28 19:53
 */
@Slf4j
@Component
public class FishMessageHandler implements IMessageHandler {
  @Autowired private TheMessageMapper theMessageMapper;
  @Autowired private MessageLogMapper messageLogMapper;
  @Autowired private UserStateMapper userStateMapper;
  @Autowired private UserBackpackMapper userBackpackMapper;
  @Autowired private FishConfigMapper fishConfigMapper;
  @Autowired private FishStateMapper fishStateMapper;

  private static FishMessageHandler fishMessageHandler;

  @Autowired private SysUserMapper sysUserMapper;
  private static String at = "[CQ:at,qq=";
  private static String at1 = "]";

  @PostConstruct
  public void init() throws Exception {
    fishMessageHandler = this;
    theMessageMapper = this.theMessageMapper;
    sysUserMapper = this.sysUserMapper;
    messageLogMapper = this.messageLogMapper;
    userStateMapper = this.userStateMapper;
    userBackpackMapper = this.userBackpackMapper;
    fishConfigMapper = this.fishConfigMapper;
    fishStateMapper = this.fishStateMapper;
  }

  @Override
  public List<String> listHandler(Massage messagePojo, Context context) {
    return Arrays.asList(handler(messagePojo, context));
  }

  @Override
  public String handler(Massage messagePojo, Context context) {
    try {
      MessageParam messageParam = context.getMessageParam();
      String message = messageParam.getMessage();
      String senderId = messageParam.getSenderId();
      String selfId = messageParam.getSelfId();
      Random random = new Random();
      SysUserExample sysUserExample = new SysUserExample();
      SysUserExample.Criteria criteria1 = sysUserExample.createCriteria();
      criteria1.andJqrQqEqualTo(selfId);
      criteria1.andUserQqEqualTo(senderId);
      List<SysUser> sysUsers = fishMessageHandler.sysUserMapper.selectByExample(sysUserExample);
      if (CollectionUtils.isEmpty(sysUsers)) {
        return at + messageParam.getSenderId() + at1 + "当前QQ未创建账号,请发送'签到'创建账号!";
      }
      SysUser sysUser = sysUsers.get(0);
      if (message.equals("游戏2")) {
        MessageLogExample messageLogExample = new MessageLogExample();
        MessageLogExample.Criteria criteria3 = messageLogExample.createCriteria();
        criteria3.andJqrQqEqualTo(selfId);
        criteria3.andUserQqEqualTo(senderId);
        criteria3.andMessageLike("游戏2-");
        criteria3.andSendDateGreaterThan(DateUtils.getNowDayStart());
        List<MessageLog> messageLogs =
            fishMessageHandler.messageLogMapper.selectByExample(messageLogExample);
        if (CollectionUtils.isNotEmpty(messageLogs)) {
          MessageLogExample messageLogExample2 = new MessageLogExample();
          MessageLogExample.Criteria criteria4 = messageLogExample2.createCriteria();
          criteria4.andJqrQqEqualTo(selfId);
          criteria4.andUserQqEqualTo(senderId);
          criteria4.andMessageLike("结束钓鱼-");
          criteria4.andSendDateGreaterThan(DateUtils.getNowDayStart());
          List<MessageLog> messageLogs1 =
              fishMessageHandler.messageLogMapper.selectByExample(messageLogExample2);
          return at
                  + messageParam.getSenderId()
                  + at1
                  + "今日已钓鱼!"
                  + (messageLogs1.size() > 0 ? "" : "但未结束,请继续钓鱼!");
        } else {
          UserBackpackExample userBackpackExample = new UserBackpackExample();
          UserBackpackExample.Criteria criteria5 = userBackpackExample.createCriteria();
          criteria5.andJqrQqEqualTo(selfId);
          criteria5.andUserQqEqualTo(senderId);
          List<UserBackpack> userBackpacks =
              fishMessageHandler.userBackpackMapper.selectByExample(userBackpackExample);
          UserBackpack userBackpack = new UserBackpack();

          if (CollectionUtils.isEmpty(userBackpacks)) {
            userBackpack.setJqrQq(messageParam.getSelfId());
            userBackpack.setUserQq(messageParam.getSenderId());
            userBackpack.setBoutiqueBait(0);
            userBackpack.setPremiumBait(0);
            userBackpack.setPlainBait(0);
            fishMessageHandler.userBackpackMapper.insertSelective(userBackpack);
            return "你没有鱼饵不可钓鱼!";
          } else {
            userBackpack = userBackpacks.get(0);
            if (userBackpack.getPlainBait() == 0
                && userBackpack.getPremiumBait() == 0
                && userBackpack.getBoutiqueBait() == 0) {
              return "你没有鱼饵不可钓鱼!";
            }
          }
          MessageLog messageLog = new MessageLog();
          messageLog.setMessage("游戏2-");
          messageLog.setJqrQq(selfId);
          messageLog.setUserQq(senderId);
          messageLog.setSendDate(new Date());
          fishMessageHandler.messageLogMapper.insertSelective(messageLog);
          return at + messageParam.getSenderId() + at1 + "钓鱼开始咯!(钓鱼-x x为鱼饵 例如:钓鱼-普通鱼饵)";
        }
      }else if (message.equals("结束钓鱼")) {
        MessageLogExample messageLogExample = new MessageLogExample();
        MessageLogExample.Criteria criteria3 = messageLogExample.createCriteria();
        criteria3.andJqrQqEqualTo(selfId);
        criteria3.andUserQqEqualTo(senderId);
        criteria3.andMessageLike("游戏2-");
        criteria3.andSendDateGreaterThan(DateUtils.getNowDayStart());
        List<MessageLog> messageLogs =
                fishMessageHandler.messageLogMapper.selectByExample(messageLogExample);
        if (CollectionUtils.isNotEmpty(messageLogs)) {
          MessageLogExample messageLogExample1 = new MessageLogExample();
          MessageLogExample.Criteria criteria4 = messageLogExample1.createCriteria();
          criteria4.andJqrQqEqualTo(selfId);
          criteria4.andUserQqEqualTo(senderId);
          criteria4.andMessageLike("结束钓鱼-");
          criteria4.andSendDateGreaterThan(DateUtils.getNowDayStart());
          List<MessageLog> messageLogs1 =
                  fishMessageHandler.messageLogMapper.selectByExample(messageLogExample1);
          if (CollectionUtils.isNotEmpty(messageLogs1)) {
            return at + messageParam.getSenderId() + at1 + "今日钓鱼已结束";
          }
          int gold = getGold(selfId, senderId);
          MessageLog messageLog = new MessageLog();
          messageLog.setMessage("结束钓鱼-");
          messageLog.setJqrQq(selfId);
          messageLog.setUserQq(senderId);
          messageLog.setSendDate(new Date());
          fishMessageHandler.messageLogMapper.insertSelective(messageLog);
          sysUser.setGold(sysUser.getGold()+gold);
          fishMessageHandler.sysUserMapper.updateByPrimaryKeySelective(sysUser);
          return at + messageParam.getSenderId() + at1 + "获得" + gold + "金币";
        } else {
          return at + messageParam.getSenderId() + at1 + "今日未开始钓鱼!";
        }
      }  else if (message.contains("钓鱼")) {
        int gold = 0;
        if (message.equals("钓鱼")) {
          return "格式错误,钓鱼-x x为鱼饵 例如:钓鱼-普通鱼饵";
        }
        String[] split = message.split("-");
        UserBackpackExample userBackpackExample = new UserBackpackExample();
        UserBackpackExample.Criteria criteria5 = userBackpackExample.createCriteria();
        criteria5.andJqrQqEqualTo(selfId);
        criteria5.andUserQqEqualTo(senderId);
        List<UserBackpack> userBackpacks =
            fishMessageHandler.userBackpackMapper.selectByExample(userBackpackExample);
        UserBackpack userBackpack = new UserBackpack();
        if (CollectionUtils.isEmpty(userBackpacks)) {
          userBackpack.setJqrQq(messageParam.getSelfId());
          userBackpack.setUserQq(messageParam.getSenderId());
          userBackpack.setBoutiqueBait(0);
          userBackpack.setPremiumBait(0);
          userBackpack.setPlainBait(0);
          fishMessageHandler.userBackpackMapper.insertSelective(userBackpack);
        } else {
          userBackpack = userBackpacks.get(0);
        }
        if ("普通鱼饵".equals(split[1])) {
          if (userBackpack.getPlainBait() < 1) {
            return "普通鱼饵不足";
          }
        } else if ("优质鱼饵".equals(split[1])) {
          if (userBackpack.getPremiumBait() < 1) {
            return "优质鱼饵不足";
          }
        } else if ("精品鱼饵".equals(split[1])) {
          if (userBackpack.getBoutiqueBait() < 1) {
            return "精品鱼饵不足";
          }
        } else {
          return "格式错误,钓鱼-x x为鱼饵 例如:钓鱼-普通鱼饵";
        }
        String res = "";
        String str = "";
        MessageLogExample messageLogExample = new MessageLogExample();
        MessageLogExample.Criteria criteria3 = messageLogExample.createCriteria();
        criteria3.andJqrQqEqualTo(selfId);
        criteria3.andUserQqEqualTo(senderId);
        criteria3.andMessageLike("游戏2-");
        criteria3.andSendDateGreaterThan(DateUtils.getNowDayStart());
        List<MessageLog> messageLogs =
            fishMessageHandler.messageLogMapper.selectByExample(messageLogExample);
        FishStateExample fishStateExample = new FishStateExample();
        FishStateExample.Criteria criteria2 = fishStateExample.createCriteria();
        criteria2.andJqrQqEqualTo(selfId);
        criteria2.andUserQqEqualTo(senderId);
        criteria2.andSendDateGreaterThan(DateUtils.getNowDayStart());
        List<FishState> fishStates =
            fishMessageHandler.fishStateMapper.selectByExample(fishStateExample);
        if (CollectionUtils.isNotEmpty(messageLogs)) {
          MessageLogExample messageLogExample1 = new MessageLogExample();
          MessageLogExample.Criteria criteria4 = messageLogExample1.createCriteria();
          criteria4.andJqrQqEqualTo(selfId);
          criteria4.andUserQqEqualTo(senderId);
          criteria4.andMessageLike("结束钓鱼-");
          criteria4.andSendDateGreaterThan(DateUtils.getNowDayStart());
          List<MessageLog> messageLogs1 =
                  fishMessageHandler.messageLogMapper.selectByExample(messageLogExample1);
          if (CollectionUtils.isNotEmpty(messageLogs1)) {
            return at + messageParam.getSenderId() + at1 + "今日钓鱼已结束";
          }
          FishConfigExample fishConfigExample = new FishConfigExample();
          FishConfigExample.Criteria criteria = fishConfigExample.createCriteria();
          criteria.andJqrQqEqualTo(selfId);
          List<FishConfig> fishConfigs =
              fishMessageHandler.fishConfigMapper.selectByExample(fishConfigExample);
          FishConfig fishConfig = fishConfigs.get(random.nextInt(fishConfigs.size()));
          res += "遇到了" + fishConfig.getName() + "\n";
          str += "损失了";
          MessageLog messageLog = new MessageLog();
          int i = 0;
          int s = 0;
          switch (fishConfig.getName()) {
            case "一角鲸":
              s=i =
                  fishStates.size() == 0
                      ? 0
                      : (random.nextInt(fishStates.size() >= 5 ? 5 : fishStates.size()) + 1);

              for (; i > 0; ) {
                FishState fishState = fishStates.get(random.nextInt(fishStates.size()));
                int i1 = fishState.getNum() - i;
                if (i1 > 0) {
                  fishState.setNum(i1);
                  str += i + "条" + fishState.getFishName();
                  fishMessageHandler.fishStateMapper.updateByPrimaryKeySelective(fishState);

                  i = 0;
                } else {
                  str += fishState.getNum() + "条" + fishState.getFishName() + " ";
                  fishMessageHandler.fishStateMapper.deleteByPrimaryKey(fishState.getId());
                  i -= fishState.getNum();
                }
              }
              res += "吃掉了你" + s + "条鱼" + str;
              break;
            case "邪天瓮":
              FishStateExample fishStateExample1 = new FishStateExample();
              FishStateExample.Criteria criteria7 = fishStateExample1.createCriteria();
              criteria7.andUserQqEqualTo(senderId);
              criteria7.andJqrQqEqualTo(selfId);
              criteria7.andSendDateGreaterThan(DateUtils.getNowDayStart());
              fishMessageHandler.fishStateMapper.deleteByExample(fishStateExample1);
              messageLog.setMessage("结束钓鱼-");
              messageLog.setJqrQq(selfId);
              messageLog.setUserQq(senderId);
              messageLog.setSendDate(new Date());
              fishMessageHandler.messageLogMapper.insertSelective(messageLog);
              res += "吃掉了你所有的鱼,并且你强制退出了钓鱼!";
              break;
            case "海鹦鹉":
              str += "损失了";
              String str1 = "";
              int num1 = 0;

              int num =
                  userBackpack.getBoutiqueBait()
                      + userBackpack.getPremiumBait()
                      + userBackpack.getPlainBait();
              num1 = num >= 3 ? 3 : num;
              int num2 = num >= 3 ? 3 : num;
              for (; num1 > 0; ) {
                List<Integer> list = new ArrayList<>();
                if (userBackpack.getBoutiqueBait() > 0) {
                  list.add(3);
                }
                if (userBackpack.getPremiumBait() > 0) {
                  list.add(2);
                }
                if (userBackpack.getPlainBait() > 0) {
                  list.add(1);
                }
                log.info(list.toString()+"  "+list.size());
                Integer i3 = list.get(random.nextInt(list.size()));
                if (i3 == 1) {
                  Integer bait = userBackpack.getPlainBait();
                  int i1 = bait - num1;
                  if (i1 >= 0) {
                    userBackpack.setPlainBait(i1);
                    str += " 普通鱼饵" + num1 + "个";
                    num1=0;
                  } else {
                    userBackpack.setPlainBait(0);
                    str += " 普通鱼饵" + bait + "个";
                    num1 -=bait;
                  }
                } else if (i3 == 2) {
                  Integer bait = userBackpack.getPremiumBait();
                  int i1 = bait - num1;
                  if (i1 >= 0) {
                    userBackpack.setPremiumBait(i1);
                    str += " 优质鱼饵" + num1 + "个";
                    num1 = 0;
                  } else {
                    userBackpack.setPremiumBait(0);
                    str += " 优质鱼饵" + bait + "个";
                    num1 -=bait;
                  }
                } else if (i3 == 3) {
                  Integer bait = userBackpack.getBoutiqueBait();
                  int i1 = bait - num1;
                  if (i1 >= 0) {
                    userBackpack.setBoutiqueBait(i1);
                    str += " 精品鱼饵" + num1 + "个";
                    num1 =0;
                  } else {
                    userBackpack.setBoutiqueBait(0);
                    str += " 精品鱼饵" + bait + "个";
                    num1 -=bait;
                  }
                }
              }
              if (num -num2 <=0) {
                messageLog.setMessage("结束钓鱼-");
                messageLog.setJqrQq(selfId);
                messageLog.setUserQq(senderId);
                messageLog.setSendDate(new Date());
                fishMessageHandler.messageLogMapper.insertSelective(messageLog);
                gold = getGold(selfId, senderId);
                str1 += " 你的鱼饵已为空已强制退出了钓鱼!获得了" + gold + "金币";
              }
              res += "吃掉了你" + num2 + "个鱼饵" + str + str1;
              break;
            case "饼干切割机":
              gold = getGold(selfId, senderId);
              messageLog.setMessage("结束钓鱼-");
              messageLog.setJqrQq(selfId);
              messageLog.setUserQq(senderId);
              messageLog.setSendDate(new Date());
              fishMessageHandler.messageLogMapper.insertSelective(messageLog);
              res += "已强制退出了钓鱼!获得了" + gold + "金币";
              break;
            case "企鹅":
              str += "损失了";
              s=i =
                  fishStates.size() == 0
                      ? 0
                      : (random.nextInt(fishStates.size() >= 1 ? 1 : fishStates.size()) + 1);
              for (; i > 0; ) {
                FishState fishState = fishStates.get(random.nextInt(fishStates.size()));
                int i1 = fishState.getNum() - i;
                if (i1 > 0) {
                  fishState.setNum(i1);
                  str += i + "条" + fishState.getFishName();
                  fishMessageHandler.fishStateMapper.updateByPrimaryKeySelective(fishState);

                  i = 0;
                } else {
                  str += fishState.getNum() + "条" + fishState.getFishName() + " ";
                  fishMessageHandler.fishStateMapper.deleteByPrimaryKey(fishState.getId());
                  i -= fishState.getNum();
                }
              }
              res += "你喂了" + s + "条鱼" + str;
              break;
            case "月岩企鹅":
              str += "损失了";
              s=i =
                  fishStates.size() == 0
                      ? 0
                      : (random.nextInt(fishStates.size() >= 1 ? 1 : fishStates.size()) + 1);
              for (; i > 0; ) {
                FishState fishState = fishStates.get(random.nextInt(fishStates.size()));
                int i1 = fishState.getNum() - i;
                if (i1 > 0) {
                  fishState.setNum(i1);
                  str += i + "条" + fishState.getFishName();
                  fishMessageHandler.fishStateMapper.updateByPrimaryKeySelective(fishState);

                  i = 0;
                } else {
                  str += fishState.getNum() + "条" + fishState.getFishName() + " ";
                  fishMessageHandler.fishStateMapper.deleteByPrimaryKey(fishState.getId());
                  i -= fishState.getNum();
                }
              }
              res += "你喂了" + s + "条鱼" + str;
              break;
            case "海黾":
              s=i =
                  fishStates.size() == 0
                      ? 0
                      : (random.nextInt(fishStates.size() >= 5 ? 5 : fishStates.size()) + 1);
              for (; i > 0; ) {
                FishState fishState = fishStates.get(random.nextInt(fishStates.size()));
                int i1 = fishState.getNum() - i;
                if (i1 > 0) {
                  fishState.setNum(i1);
                  str += i + "条" + fishState.getFishName();
                  fishMessageHandler.fishStateMapper.updateByPrimaryKeySelective(fishState);
                  i = 0;
                } else {
                  str += fishState.getNum() + "条" + fishState.getFishName() + " ";
                  fishMessageHandler.fishStateMapper.deleteByPrimaryKey(fishState.getId());
                  i -= fishState.getNum();
                }
              }
              gold = getGold(selfId, senderId);
              res += "吃掉了你" + s + "条鱼" + str + "\n已强制退出了钓鱼!获得了" + gold + "金币";
              messageLog.setMessage("结束钓鱼-");
              messageLog.setJqrQq(selfId);
              messageLog.setUserQq(senderId);
              messageLog.setSendDate(new Date());
              fishMessageHandler.messageLogMapper.insertSelective(messageLog);
              break;
            case "草鳄鱼":
              int i1 = random.nextInt(8);
              str += ",获取了";
              if (i1 == 0) {
                userBackpack.setBoutiqueBait(userBackpack.getBoutiqueBait() + 5);
                str += "5个精品鱼饵";
              } else if (i1 > 3) {
                userBackpack.setPremiumBait(userBackpack.getPremiumBait() + 5);
                str += "5个优质鱼饵";
              } else {
                userBackpack.setPlainBait(userBackpack.getPlainBait() + 5);
                str += "5个普通鱼饵";
              }
              res += "害怕的扔下了鱼饵," + str;
              break;
            case "岩石大白鲨":
              FishStateExample fishStateExample2 = new FishStateExample();
              FishStateExample.Criteria criteria6 = fishStateExample2.createCriteria();
              criteria6.andUserQqEqualTo(senderId);
              criteria6.andJqrQqEqualTo(selfId);
              criteria6.andSendDateGreaterThan(DateUtils.getNowDayStart());
              fishMessageHandler.fishStateMapper.deleteByExample(fishStateExample2);
              res += "吃掉了你所有的鱼!";
              break;
            default:
              int i2 = random.nextInt(10);
              int b = 0;
              if ("普通鱼饵".equals(split[1])) {
                b = 5;
                userBackpack.setPlainBait(userBackpack.getPlainBait()-1);
              } else if ("优质鱼饵".equals(split[1])) {
                b = 2;
                userBackpack.setPremiumBait(userBackpack.getPremiumBait() - 1);
              } else if ("精品鱼饵".equals(split[1])) {
                b = 0;
                userBackpack.setBoutiqueBait(userBackpack.getBoutiqueBait() - 1);
              }

              res += "消耗了" + split[1];
              if (i2 < b) {
                res += ",鱼儿脱钩了";
              } else {
                FishStateExample fishStateExample3 = new FishStateExample();
                FishStateExample.Criteria criteria8 = fishStateExample3.createCriteria();
                criteria8.andUserQqEqualTo(senderId);
                criteria8.andJqrQqEqualTo(selfId);
                criteria8.andSendDateGreaterThan(DateUtils.getNowDayStart());
                criteria8.andFishNameEqualTo(fishConfig.getName());
                List<FishState> fishStates1 =
                    fishMessageHandler.fishStateMapper.selectByExample(fishStateExample3);
                FishState fishState = new FishState();

                if (CollectionUtils.isEmpty(fishStates1)) {
                  fishState.setFishName(fishConfig.getName());
                  fishState.setJqrQq(selfId);
                  fishState.setUserQq(senderId);
                  fishState.setSendDate(new Date());
                  fishState.setNum(0);
                  fishMessageHandler.fishStateMapper.insertSelective(fishState);
                  fishStates1 =
                      fishMessageHandler.fishStateMapper.selectByExample(fishStateExample3);
                }
                fishState = fishStates1.get(0);
                fishState.setNum(fishState.getNum() + 1);
                res += ",获得了" + fishConfig.getName() + "1条";
                fishMessageHandler.fishStateMapper.updateByPrimaryKeySelective(fishState);
              }
              if (userBackpack.getPlainBait() == 0
                      && userBackpack.getPremiumBait() == 0
                      && userBackpack.getBoutiqueBait() == 0) {
                gold = getGold(selfId, senderId);
                res+="你的鱼饵为空,已强制退出钓鱼!获得"+gold+"金币";
                messageLog.setMessage("结束钓鱼-");
                messageLog.setJqrQq(selfId);
                messageLog.setUserQq(senderId);
                messageLog.setSendDate(new Date());
                fishMessageHandler.messageLogMapper.insertSelective(messageLog);
              }
          }
          fishMessageHandler.userBackpackMapper.updateByPrimaryKeySelective(userBackpack);
          sysUser.setGold(sysUser.getGold()+gold);
          fishMessageHandler.sysUserMapper.updateByPrimaryKeySelective(sysUser);
          return at + messageParam.getSenderId() + at1 + res+"\n发送'钓鱼-x'即可继续! 发送'结束钓鱼'即可结束!";
        } else {
          return at + messageParam.getSenderId() + at1 + "你未开始钓鱼!请发'游戏2'开始游戏";
        }
      } else if (message.equals("查看鱼护")) {
        FishStateExample fishStateExample = new FishStateExample();
        FishStateExample.Criteria criteria = fishStateExample.createCriteria();
        criteria.andUserQqEqualTo(senderId);
        criteria.andJqrQqEqualTo(selfId);
        criteria.andSendDateGreaterThan(DateUtils.getNowDayStart());
        List<FishState> fishStates =
            fishMessageHandler.fishStateMapper.selectByExample(fishStateExample);
        if (CollectionUtils.isNotEmpty(fishStates)) {
          String res = "";
          for (FishState fishState : fishStates) {
            FishConfigExample fishConfigExample = new FishConfigExample();
            FishConfigExample.Criteria criteria2 = fishConfigExample.createCriteria();
            criteria2.andJqrQqEqualTo(selfId);
            criteria2.andNameEqualTo(fishState.getFishName());
            List<FishConfig> fishConfigs =
                    fishMessageHandler.fishConfigMapper.selectByExample(fishConfigExample);
            res += fishState.getFishName() + " " + fishState.getNum() + "条 单价"+fishConfigs.get(0).getGold()+"金币\\n";
          }
          HttpUtil.post(
              messageParam.getUrl() + "/send_group_forward_msg",
              "{\n"
                  + "    \"group_id\": \""
                  + messageParam.getGroupId()
                  + "\",\n"
                  + "    \"messages\": [\n"
                  + "        {\n"
                  + "            \"type\": \"node\",\n"
                  + "            \"data\": {\n"
                  + "                \"user_id\": \""
                  + messageParam.getSelfId()
                  + "\",\n"
                  + "                \"nickname\": \"云梦星机器人\",\n"
                  + "                \"content\":\""
                  + messageParam.getSenderId()
                  + "你鱼护的鱼:"
                  + "\"\n"
                  + "            }\n"
                  + "        },\n"
                  + "        {\n"
                  + "            \"type\": \"node\",\n"
                  + "            \"data\": {\n"
                  + "                \"user_id\": \""
                  + messageParam.getSelfId()
                  + "\",\n"
                  + "                \"nickname\": \"云梦星机器人\",\n"
                  + "                \"content\":\""
                  + res
                  + "\"\n"
                  + "            }\n"
                  + "        }\n"
                  + "    ]\n"
                  + "}");
          return "鱼护消息请看转发消息";
        } else {
          return "你的鱼护是空的";
        }
      }
      return "111111111111111";
    } catch (Exception e) {
      e.printStackTrace();
      return e.getMessage();
    }
  }

  public int getGold(String selfId, String senderId) {
    FishStateExample fishStateExample = new FishStateExample();
    FishStateExample.Criteria criteria = fishStateExample.createCriteria();
    criteria.andUserQqEqualTo(senderId);
    criteria.andJqrQqEqualTo(selfId);
    criteria.andSendDateGreaterThan(DateUtils.getNowDayStart());
    List<FishState> fishStates =
        fishMessageHandler.fishStateMapper.selectByExample(fishStateExample);
    int gold = 0;
    if (CollectionUtils.isNotEmpty(fishStates)) {
      for (FishState fishState : fishStates) {
        FishConfigExample fishConfigExample = new FishConfigExample();
        FishConfigExample.Criteria criteria2 = fishConfigExample.createCriteria();
        criteria2.andJqrQqEqualTo(selfId);
        criteria2.andNameEqualTo(fishState.getFishName());
        List<FishConfig> fishConfigs =
            fishMessageHandler.fishConfigMapper.selectByExample(fishConfigExample);
        FishConfig fishConfig = fishConfigs.get(0);
        gold += (fishConfig.getGold() * fishState.getNum());
      }
    }
    fishMessageHandler.fishStateMapper.deleteByExample(fishStateExample);
    return gold;
  }
}
